package ThreadPool;

/**
 * @author wang'ji'cheng
 * @date 2025/7/25
 */
public class ThreadDemo7 {
    public static void main(String[] args) {
        Object objA = new Object();
        Object objB = new Object();

        new Thread(() -> {
            for (int i = 1; i <= 1000; i++) {
                System.out.println("第"+i+"次输出");
                synchronized (objA) {
                    synchronized (objB) {
                        System.out.println("线程1获取了A锁，将要获取B锁");
                    }
                }
            }
        }).start();

        new Thread(() -> {
            for (int i = 1; i <= 1000; i++) {
                System.out.println("第"+i+"次输出");
                synchronized (objB) {
                    synchronized (objA) {
                        System.out.println("线程2获取了B锁，将要获取B锁");
                    }
                }
            }
        }).start();
        System.out.println("死锁了吗？");
    }



}
